package com.htjx.mall.admin.controllers.interceptors;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.util.WebUtils;

/**
 * 登录验证拦截器
 * 
 * @author jingrenlang
 * 
 */
public class LoginCheckInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		
		String uri = request.getRequestURI();
		if (uri.contains("login")) {
			return true;
		}
		Object adminName = WebUtils.getSessionAttribute(request, "admin_name");
		if (adminName == null) {
			response.sendRedirect("/login.jsp");
			return false;
		}
		
		return true;
	}

}
